//
//  GQJAnalyze.m
//  TotalDemo
//
//  Created by gujian on 16/7/19.
//  Copyright © 2016年 gujian. All rights reserved.
//

#import "GQJAnalyze.h"
#import "GQJContainerController.h"
#import "GQJFloatingButtonController.h"
#import "GQJWindow.h"
#import "GQJAnalyzeWindowTouchesHandling.h"

OBJC_EXTERN int _objc_rootRetainCount(id);

static const NSUInteger kGQJFloatingButtonSize = 52.0;

@interface GQJAnalyze()<GQJAnalyzeWindowTouchesHandling>
{
    GQJFloatingButtonController *_floatingButtonController;
    GQJContainerController *_containerController;
    
    
}

@property (nonatomic, strong) GQJWindow *gqjWindow;

@end

@implementation GQJAnalyze

- (void)enable
{
    _containerController = [GQJContainerController new];
    _gqjWindow = [[GQJWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
    _gqjWindow.rootViewController = _containerController;
    _gqjWindow.touchesDelegate = self;
    _gqjWindow.hidden = NO;
    
    [self showFloatingButton];
    
}

- (void)disable
{
    [self hideFloatingButton];
    _gqjWindow = nil;
}

- (void)showFloatingButton
{
    _floatingButtonController = [GQJFloatingButtonController new];
    [_containerController presentViewController:_floatingButtonController size:CGSizeMake(kGQJFloatingButtonSize, kGQJFloatingButtonSize)];
}


- (void)hideFloatingButton
{
    [_containerController dismissCurrentViewController];
    _floatingButtonController = nil;
}


#pragma mark - GQJAnalyzeWindowTouchesHandling
- (BOOL)window:(UIWindow *)window shouldReceiveTouchAtPoint:(CGPoint)point
{
    return CGRectContainsPoint(_floatingButtonController.view.bounds, [_floatingButtonController.view convertPoint:point fromView:_gqjWindow]);
}

@end
